<template>
  <div class="home">
    <el-container>
      <el-header>
        <p>电商后台</p>
        <el-button @click="outloginhandel">退出登录</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '65px' : '200px'">
          <p @click="isCollapse = !isCollapse"><i :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"></i></p>
          <el-menu :collapse="isCollapse" :default-active="$route.path" class="el-menu-vertical-demo" unique-opened
            router background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
            <el-submenu :index="item.id + ''" v-for="item in menuslist" :key="item.id">
              <template slot="title">
                <i class="el-icon-user-solid"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group v-for="childitem in item.children" :key="childitem.id">
                <el-menu-item :index="'/' + childitem.path">{{ childitem.authName }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getmenusAPI } from '../utlis/api//menus/menusapi'

export default {
  name: 'HomeView',
  data() {
    return {
      menuslist: [],
      icon: [
        { id: 125, icon: 'el-icon-user-solid' },
        { id: 103, icon: 'el-icon-s-tools' },
        { id: 101, icon: 'el-icon-s-goods' },
        { id: 102, icon: 'el-icon-s-order' },
        { id: 145, icon: 'el-icon-s-data' },
      ],
      isCollapse: false
    }
  },
  methods: {
    outloginhandel() {
      localStorage.removeItem('token')
      location.href = '/login'
    }
  },
  created() {
    getmenusAPI().then((res) => {
      console.log(res);
      if (res.data.meta.status == 200) {
        this.menuslist = res.data.data
        this.$message({
          message: res.data.meta.msg,
          type: 'success'
        });
      } else {
        this.$message({
          message: res.data.meta.msg,
          type: 'error'
        });
      }
    })
  }
}
</script>
<style lang="scss" scoped>
.el-header {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  height: calc(100vh - 60px);
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  height: calc(100vh - 60px);
}
</style>
